﻿<c:BaseControl x:Class="personalplaner.gui.plugins.dienstplan.views.DienstPlanPlugin"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             xmlns:c="clr-namespace:personalplaner.common.controls;assembly=personalplaner.common"
             xmlns:bs="clr-namespace:personalplaner.business.stamm;assembly=personalplaner.business"
             xmlns:conv="clr-namespace:personalplaner.common.converters;assembly=personalplaner.common"
             xmlns:vm="clr-namespace:personalplaner.common.mvvm.factory;assembly=personalplaner.common"
             xmlns:fac="clr-namespace:personalplaner.gui.plugins.dienstplan.viewmodels.factories"
               xmlns:k="clr-namespace:personalplaner.common.themes;assembly=personalplaner.common"
               vm:ViewModelLoader.FactoryType="{x:Type fac:DienstPlanPluginModelFactory}">
    
    <Control.Resources>
        
        <conv:ColorToSolidColorBrushConverter x:Key="colorToBrush"/>

        <DataTemplate DataType="{x:Type bs:Dienst}">
            <Grid Margin="0,0,20,0" Width="150" x:Name="itemgrid">
                <Grid.ToolTip>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{Binding Name}" />
                        <TextBlock Text="/" Margin="5,0,5,0" Grid.Column="1"/>
                        <TextBlock Text="{Binding KurzText}" Grid.Column="2"/>
                        <Border Width="15" Height="13" Background="{Binding Color, Converter={StaticResource colorToBrush}}" Grid.Column="3" Margin="5,0,0,-3" />
                    </Grid>
                </Grid.ToolTip>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <Grid.OpacityMask>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                        <GradientStop Offset="0.0" Color="Black" />
                        <GradientStop Offset="0.8" Color="Black" />
                        <GradientStop Offset="1.0" Color="Transparent" />
                    </LinearGradientBrush>
                </Grid.OpacityMask>

                <!-- Create a trasparent border that keeps the width static -->
                <Border Background="Transparent" Width="150" Grid.ColumnSpan="2"/>

                <TextBlock Text="{Binding Name}" x:Name="name" Foreground="{Binding Color, Converter={StaticResource colorToBrush}}" />
                <TextBlock Text="{Binding KurzText}" x:Name="kurztext" Grid.Column="1" Foreground="{Binding Color, Converter={StaticResource colorToBrush}}" >

                </TextBlock>
            </Grid>

            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Color}" Value="{x:Null}">
                    <Setter TargetName="name" Property="Foreground" Value="Black"/>
                    <Setter TargetName="kurztext" Property="Foreground" Value="Black"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsNew}" Value="True">
                    <Setter TargetName="itemgrid" Property="ToolTip" Value="{x:Null}"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>


        <!--<ControlTemplate x:Key="ExpanderToggleButton" TargetType="ToggleButton">
            <Border Name="Border" Background="Transparent">

                <Path SnapsToDevicePixels="True" IsHitTestVisible="False" Name="Arrow" Fill="#0FFF" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Right" VerticalAlignment="Center" Data="M 5 0 L 5 8 L 0 4 Z" Stroke="{DynamicResource {x:Static k:ResourceKeys.GlyphBrush}}" StrokeThickness="0.5">
                    <Path.RenderTransform>
                        <RotateTransform Angle="0" />
                    </Path.RenderTransform>
                </Path>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsChecked" Value="False">
                    <Trigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="Arrow" Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(RotateTransform.Angle)" Duration="0:0:0.2" To="-90" DecelerationRatio="1" />
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.EnterActions>
                    <Trigger.ExitActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation  Storyboard.TargetName="Arrow" Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(RotateTransform.Angle)" Duration="0:0:0.2" AccelerationRatio="1" />
                            </Storyboard>
                        </BeginStoryboard>
                    </Trigger.ExitActions>
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="#81F5F5F5"/>
                    <Setter TargetName="Arrow" Property="Fill" Value="#81F5F5F5" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        
        <Style TargetType="Expander">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Expander">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition  Name="ContentRow" Height="0"/>
                                </Grid.RowDefinitions>
                                <Border BorderBrush="Transparent" Background="Transparent" Name="Content">
                                    <ContentPresenter />
                                </Border>
                            </Grid>
                            
                            <ToggleButton Grid.Column="1" VerticalAlignment="Top"
                                          IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                          Template="{StaticResource ExpanderToggleButton}" Margin="5"/>
                            
                        </Grid>

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsExpanded" Value="True">
                                <Setter TargetName="ContentRow" Property="Height" Value="{Binding ElementName=Content, Path=DesiredHeight}" />
                            </Trigger>
                        </ControlTemplate.Triggers>


                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>-->
        
    </Control.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ComboBox ItemsSource="{Binding ArbeitsPlanHeaderList}" SelectedItem="{Binding SelectedArbeitsPlanHeader}" DisplayMemberPath="Name" Foreground="#E1000000"/>

        <c:ColorPicker SelectedColor="{Binding SelectedColor}" Grid.Row="1" Margin="0,5,0,5"/>

        <Border Grid.Row="2" BorderBrush="#FF707070" BorderThickness="1" CornerRadius="1" Background="#E1FFFFFF" Padding="2">
            <DockPanel LastChildFill="True">
                <!--<Expander HorizontalAlignment="Stretch" DockPanel.Dock="Top" >
                    <TextBox />
                </Expander>-->
                <TextBox DockPanel.Dock="Top" FontSize="10" Text="{Binding FilterString, UpdateSourceTrigger=PropertyChanged}" FontWeight="Heavy" />
                <ListBox DockPanel.Dock="Bottom" ItemsSource="{Binding Dienste}" SelectedItem="{Binding SelectedDienst}" BorderThickness="0" Background="#E1FFFFFF" ScrollViewer.HorizontalScrollBarVisibility="Hidden" FontWeight="Medium" />
            </DockPanel>
        </Border>
        <!--<ListBox Grid.Row="2" ItemsSource="{Binding Dienste}" SelectedItem="{Binding SelectedDienst}" Background="#E1FFFFFF" ScrollViewer.HorizontalScrollBarVisibility="Hidden" FontWeight="Medium" />-->
    </Grid>
</c:BaseControl>
